/**
 * 
 */
package com.laozhao.deliveryManager.view.master;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.laozhao.deliveryManager.business.MasterServer;
import com.laozhao.deliveryManager.model.UserModel;

/**
 * @author laozhao
 *
 */
public class UserUI extends JPanel  {
	
	protected UserModel user;
	
	JLabel userCodeLb;
	protected JTextField userCodeTx;
	JLabel userNameLb;
	protected JTextField userNameTx;
	
	protected JButton searchButton;
	protected JButton addButton;
	protected JButton delButton;
	protected JButton saveButton;
	
	protected JTable table;
	protected TableModel model;// = new TableModel(new String[]{"2","3"},new String[]{"2","3"});

	// server
	private MasterServer mServer;
	
	
	public UserUI(){
		super();
		this.setName("用户管理");
		mServer = new MasterServer();
	}

	public void setUser(UserModel user) {
		this.user = user;
	}


	public void init(){
		initComponents();
	}
	/**
	 * 初始化画面
	 */
	private void initComponents() {
		JPanel searchPane = new JPanel(new GridLayout(2,2,10,10));
		buileSearchPane(searchPane);
		
		JPanel buttonPane = new JPanel(new GridLayout(1,4,10,10));
		buildButtonPane(buttonPane);
		
		JScrollPane tablePane1 = new JScrollPane();
		buileTablePane(tablePane1);
		JScrollPane tablePane = new JScrollPane(table);
		
		
		JPanel conPane = new JPanel();
		conPane.add(searchPane);
		conPane.add(buttonPane);
		
		this.setLayout(new BorderLayout());
		this.add(conPane,BorderLayout.NORTH);
		this.add(tablePane,BorderLayout.CENTER);
	}

	private void buileTablePane(JScrollPane tablePane) {

		String[] tableTitle={"书名","出版社","作者","地址","出版日期","定价","评论"};
		Object[][] tableData = new Object[0][0];
		
		model = new DefaultTableModel(tableData,tableTitle);
		table = new JTable(model);
//		tablePane.add(table);
	}

	private void buildButtonPane(JPanel buttonPane) {
		searchButton = new JButton("检索");
		addButton = new JButton("添加");
		delButton = new JButton("删除");
		saveButton = new JButton("保存");
		

		buttonPane.add(searchButton);
		buttonPane.add(addButton);
		buttonPane.add(delButton);
		buttonPane.add(saveButton);
		
	}

	private void buileSearchPane(JPanel searchPane) {
		userCodeLb = new JLabel("用户编码");
		userNameLb = new JLabel("用户名称");
		userCodeTx = new JTextField();
		userNameTx = new JTextField();
		
		searchPane.add(userCodeLb);
		searchPane.add(userNameLb);
		searchPane.add(userCodeTx);
		searchPane.add(userNameTx);
		
	}
}
